package com.ruoyi.web.controller.consume;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consume.domain.BladeApplyTemporaryCon;
import com.ruoyi.consume.service.IBladeApplyTemporaryConService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 刀片临时领用Controller
 *
 * @author ruoyi
 * @date 2021-07-27
 */
@Api("刀片临时领用")
@RestController
@RequestMapping("/consume/bladetemap")
public class BladeApplyTemporaryConController extends BaseController
{
    @Autowired
    private IBladeApplyTemporaryConService bladeApplyTemporaryService;

    /**
     * 查询刀片临时领用列表
     */
    @ApiOperation("查询刀片临时领用列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:bladetemap:list')")
    @GetMapping("/list")
    public TableDataInfo list(BladeApplyTemporaryCon bladeApplyTemporaryCon)
    {
        startPage();
        List<BladeApplyTemporaryCon> list = bladeApplyTemporaryService.selectBladeApplyTemporaryList(bladeApplyTemporaryCon);
        return getDataTable(list);
    }

    /**
     * 导出刀片临时领用列表
     */
    @PreAuthorize("@ss.hasPermi('consume:bladetemap:export')")
    @Log(title = "刀片临时领用", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BladeApplyTemporaryCon bladeApplyTemporaryCon)
    {
        List<BladeApplyTemporaryCon> list = bladeApplyTemporaryService.selectBladeApplyTemporaryList(bladeApplyTemporaryCon);
        ExcelUtil<BladeApplyTemporaryCon> util = new ExcelUtil<BladeApplyTemporaryCon>(BladeApplyTemporaryCon.class);
        return util.exportExcel(list, "刀片临时领用数据");
    }

    /**
     * 获取刀片临时领用详细信息
     */
    @PreAuthorize("@ss.hasPermi('consume:bladetemap:query')")
    @GetMapping(value = "/{bladeApplyTemporaryId}")
    public AjaxResult getInfo(@PathVariable("bladeApplyTemporaryId") Long bladeApplyTemporaryId)
    {
        return AjaxResult.success(bladeApplyTemporaryService.selectBladeApplyTemporaryById(bladeApplyTemporaryId));
    }

    /**
     * 新增刀片临时领用
     */
    @PreAuthorize("@ss.hasPermi('consume:bladetemap:add')")
    @Log(title = "刀片临时领用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BladeApplyTemporaryCon bladeApplyTemporaryCon)
    {
        return toAjax(bladeApplyTemporaryService.insertBladeApplyTemporary(bladeApplyTemporaryCon));
    }

    /**
     * 修改刀片临时领用
     */
    @PreAuthorize("@ss.hasPermi('consume:bladetemap:edit')")
    @Log(title = "刀片临时领用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BladeApplyTemporaryCon bladeApplyTemporaryCon)
    {
        return toAjax(bladeApplyTemporaryService.updateBladeApplyTemporary(bladeApplyTemporaryCon));
    }

    /**
     * 删除刀片临时领用
     */
    @PreAuthorize("@ss.hasPermi('consume:bladetemap:remove')")
    @Log(title = "刀片临时领用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bladeApplyTemporaryIds}")
    public AjaxResult remove(@PathVariable Long[] bladeApplyTemporaryIds)
    {
        return toAjax(bladeApplyTemporaryService.deleteBladeApplyTemporaryByIds(bladeApplyTemporaryIds));
    }

    /**
     * 更新库存量表
     */
    @ApiOperation("更新库存量表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:bladetemap:amount')")
    @Log(title = "刀片临时领用", businessType = BusinessType.UPDATE)
    @PutMapping("/amount")
    public AjaxResult amount(@RequestBody BladeApplyTemporaryCon bladeApplyTemporaryCon)
    {
        return toAjax(bladeApplyTemporaryService.updateAmount(bladeApplyTemporaryCon));
    }

    /**
     * 更新领用状态
     */
    @ApiOperation("更新领用状态")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:bladetemap:consu')")
    @Log(title = "刀片临时领用", businessType = BusinessType.UPDATE)
    @PutMapping("/consu/{bladeApplyTemporaryId}")
    public AjaxResult consume(@PathVariable("bladeApplyTemporaryId") Long bladeApplyTemporaryId)
    {
        return toAjax(bladeApplyTemporaryService.updateConsumeStatus(bladeApplyTemporaryId));
    }

    /**
     * 退回操作
     */
    @ApiOperation("退回操作")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:bladetemap:back')")
    @Log(title = "刀片临时领用", businessType = BusinessType.UPDATE)
    @PutMapping("/back/{bladeApplyTemporaryId}")
    public AjaxResult back(@PathVariable("bladeApplyTemporaryId") Long bladeApplyTemporaryId)
    {
        return toAjax(bladeApplyTemporaryService.updateApprovalStatus(bladeApplyTemporaryId));
    }
}
